import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:pornhub_app/components/base_refresh/base_refresh_widget.dart';
import 'package:pornhub_app/components/no_more/no_data.dart';
import 'package:pornhub_app/utils/color.dart';
import 'package:pornhub_app/utils/extension.dart';
import 'package:pornhub_app/views/engagement/controllers/engagement_station_more_page_controller.dart';
import 'package:pornhub_app/views/engagement/views/engagement_list_cell.dart';

class EngagementStationMorePage
    extends GetView<EngagementStationMorePageController> {
  const EngagementStationMorePage({super.key});

  AppBar _buildAppBar(
      BuildContext context, EngagementStationMorePageController controller) {
    return AppBar(
      leading: Container(
        padding: EdgeInsets.all(20.w),
        child: Image.asset(
          "assets/images/icons/base_ic_back_grey.png",
          width: 9.w,
          height: 16.w,
        ),
      ).onOpaqueTap(() {
        onBackClick(context);
      }),
      title: Text(controller.stationName ?? '',
          textAlign: TextAlign.center,
          style: TextStyle(
            color: COLOR.hexColor("#333333"),
            fontSize: 16.w,
            fontWeight: FontWeight.w400,
          )),
      centerTitle: true,
      bottom: PreferredSize(
        preferredSize: Size.fromHeight(1.w),
        child: Container(
          height: 1.w,
          color: COLOR.hexColor("#F0F0F0"),
        ),
      ),
    );
  }

  void onBackClick(BuildContext context) {
    Navigator.pop(context);
  }

  @override
  Widget build(BuildContext context) {
    return GetBuilder<EngagementStationMorePageController>(
      builder: (_) {
        return Scaffold(
          appBar: _buildAppBar(context, controller),
          body: BaseRefreshWidget(
            controller,
            child: Padding(
              padding: EdgeInsets.only(top: 14.w),
              child: ListView.builder(
                itemCount:
                    _.engagementList.isNotEmpty ? _.engagementList.length : 1,
                itemBuilder: (context, index) {
                  if (_.engagementList.isNotEmpty) {
                    return EngagementListCell(
                      data: _.engagementList[index],
                    );
                  } else {
                    return const NoData().marginOnly(top: 200.w);
                  }
                },
              ),
            ),
          ),
        );
      },
    );
  }
}
